package config

import (
	"path"
	"runtime"
	"sync"

	"github.com/cdongyang/library/utils"
)

var config Config
var once sync.Once

type Config struct {
	Salt   string
	Socket string
	Host   string
	Path   string
}

func GetConfig() *Config {
	once.Do(func() { // 防止用init函数外部调用时还没初始化
		utils.PanicError(utils.LoadCurrentDirJSONFile("config.json", &config))
		_, file, _, _ := runtime.Caller(0)
		config.Path = path.Join(path.Dir(file), "../")
	})
	return &config
}
